﻿using System;
using System.Collections.Generic;
using System.Data;
using DBUtility;

namespace BLL.Room
{
    /// <summary>
    /// 业务逻辑类ROOM_EQUIPMENTLAYOUT 的摘要说明。
    /// </summary>
    public class ROOM_Environment
    {
        private readonly OracleDAL.Room.ROOM_Environment dal = new OracleDAL.Room.ROOM_Environment();
        public ROOM_Environment()
        { }
        #region  成员方法
        /// <summary>
        /// 得到一个机房动力环境实例
        /// </summary>
        /// <param name="ROOMID">机房ID</param>
        /// <returns></returns>
        public Model.Room.ROOM_Environment GetModel(string ROOMID)
        {
            return dal.GetModel(ROOMID);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Room.ROOM_Environment> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Room.ROOM_Environment> DataTableToList(DataTable dt)
        {
            List<Model.Room.ROOM_Environment> modelList = new List<Model.Room.ROOM_Environment>();
            if (dt.Rows.Count > 0)
            {
                DataTable dtNew = OracleHelper.SelectDistinct("room", dt, "ROOMID");

                int rowsCount = dtNew.Rows.Count;

                if (rowsCount > 0)
                {
                    for (int i = 0; i < rowsCount; i++)
                    {
                        Model.Room.ROOM_Environment model;
                        model = dal.GetModelData(ConvertDataTable(dt, " roomid = '" + dtNew.Rows[i]["ROOMID"].ToString() + "'"));
                        modelList.Add(model);
                    }
                }

            }
            return modelList;
        }
        /// <summary>
        /// 过滤DataTable数据并形成DataTable返回
        /// </summary>
        /// <param name="dt">原数据集</param>
        /// <param name="filter">过滤条件</param>
        /// <returns></returns>
        public DataTable ConvertDataTable(DataTable dt, string filter)
        {
            System.Data.DataView dv = new System.Data.DataView(dt);
            dv.RowFilter = filter;
            return dv.ToTable();
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

         /// <summary>
        /// 获取机房信息
        /// </summary>
        /// <returns></returns>
        public List<Model.Room.ROOM_INFO> GetRoomInfo()
        {
            return dal.GetRoomInfo();
        }
        /// <summary>
        /// 获取机房信息
        /// </summary>
        /// <param name="ROOMID">机房ID</param>
        /// <returns></returns>
        public Model.Room.ROOM_INFO GetRoomInfo(string ROOMID)
        {
            return dal.GetRoomInfo(ROOMID);
        }
        /// <summary>
        /// 获取机房信息
        /// </summary>
        /// <param name="ROOMID">机房ID</param>
        /// <returns></returns>
        public Model.Room.ROOM_INFO GetRoomInfoByROOMID(string ROOMID)
        {
            return dal.GetRoomInfoByROOMID(ROOMID);
        }
        #endregion  成员方法
    }
}
